/**
 * 
 */
package action;


import model.AccountModel;
import service.AccountService;
import service.MsgService;

import com.opensymphony.xwork2.ModelDriven;

import dao.TbUser;

/**
 * @author ykss
 * 
 */
public class AccountAction extends BaseAction implements ModelDriven<AccountModel>{

	/**
	 * 2014年6月16日23:21:11
	 */
	private static final long serialVersionUID = -8534550171421612227L;
	private AccountService userService = new AccountService();
	private AccountModel account;

	public AccountModel getModel() {
		// TODO Auto-generated method stub
		return this.getAccount();
	}

	public String Login() {

//		this.session.put("role","admin");
//		return "login";
		// TODO 登陆请求，登陆完成后，将用户角色放到session【role】中，String类型
		if (userService.login((TbUser)this.getModel())) {
			this.session.put("role",
					userService.GetUserRole(this.getAccount().getUsername()));
			return "login";
		}
		MsgService.SetMessage("登陆失败", 1000, "/user_login_action", this.request);
		return "failed";
	}


	public String Logout() {
		this.session.remove("role");
		return "logout";
	}

	public void setAccount(AccountModel account) {
		this.account = account;
	}

	public AccountModel getAccount() {
		return account;
	}


}
